package com.szosen.database;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Environment;

import com.szosen.database.DaoMaster.DevOpenHelper;

public class DBService {
	private static DevOpenHelper mHelper;
	private static SQLiteDatabase mDatabase;
	private static DaoMaster mDaoMaster;
	private static DaoSession mDaoSession;
	private static DBService sAppDB = null;

	// ****************************数据操作*************************************************
	private static HealthRecordDao mHealthRecordDao;
	private static jwsjbDao mJwsjbDao;
	private static jwsssDao mJwsssDao;
	private static jwssxDao mJwssxDao;
	private static jwswsDao mJwswsDao;
	private static base_infoDao mBase_infoDao;
	private static ExaminationDao mExaminationDao;
	private static AccessoryExaminationDao mAccessoryExaminationDao;
	private static InhospitalSituationDao mInhospitalSituationDao;
	private static MedicineSituationDao mMedicineSituationDao;
	private static NonimmuneInoculationDao mNonimmuneInoculationDao;
	private static HealthAssessmentDao mHealthAssessmentDao;
	private static Visit_infoDao mVisit_infoDao;
	private static Visit_info2Dao mVisit_info2Dao;
	private static ChineseMedicineManageDao mChineseMedicineManageDao;
	private static OldPeopleSelfCareDao mOldPeopleSelfCareDao;
	private static LifestySituationDao mLifestySituationDao;
	private static xueyaDao mxueyaDao;
	private static xueyangDao mxueyangDao;
	private static tiwenDao mtiwenDao;
	private static xuetangDao mxuetangDao;
	private static niaoyeDao mniaoyeDao;
	private static xindianDao mxindianDao;
	private static UploadRecordDao mUploadRecordDao;
	private static xuezhiDao mXuezhiDao;
	private static VisitPlanDao mVisitPlanDao;

	private DBService(Context context) {
		mHelper = new DaoMaster.DevOpenHelper(context, "health.db", null);
		mDatabase = mHelper.getWritableDatabase();
		mDaoMaster = new DaoMaster(mDatabase);
		mDaoSession = mDaoMaster.newSession();
		mHealthRecordDao = mDaoSession.getHealthRecordDao();
		mJwsjbDao = mDaoSession.getJwsjbDao();
		mJwsssDao = mDaoSession.getJwsssDao();
		mJwssxDao = mDaoSession.getJwssxDao();
		mJwswsDao = mDaoSession.getJwswsDao();
		mBase_infoDao = mDaoSession.getBase_infoDao();
		mExaminationDao = mDaoSession.getExaminationDao();
		mLifestySituationDao = mDaoSession.getLifestySituationDao();
		mAccessoryExaminationDao = mDaoSession.getAccessoryExaminationDao();
		mInhospitalSituationDao = mDaoSession.getInhospitalSituationDao();
		mMedicineSituationDao = mDaoSession.getMedicineSituationDao();
		mNonimmuneInoculationDao = mDaoSession.getNonimmuneInoculationDao();
		mHealthAssessmentDao = mDaoSession.getHealthAssessmentDao();
		mVisit_infoDao = mDaoSession.getVisit_infoDao();
		mVisit_info2Dao = mDaoSession.getVisit_info2Dao();
		mChineseMedicineManageDao = mDaoSession.getChineseMedicineManageDao();
		mOldPeopleSelfCareDao = mDaoSession.getOldPeopleSelfCareDao();
		mxueyaDao = mDaoSession.getXueyaDao();
		mxueyangDao = mDaoSession.getXueyangDao();
		mtiwenDao = mDaoSession.getTiwenDao();
		mxuetangDao = mDaoSession.getXuetangDao();
		mniaoyeDao = mDaoSession.getNiaoyeDao();
		mxindianDao = mDaoSession.getXindianDao();
		mUploadRecordDao = mDaoSession.getUploadRecordDao();
		mXuezhiDao = mDaoSession.getXuezhiDao();
		mVisitPlanDao = mDaoSession.getVisitPlanDao();
	}

	public static synchronized DBService getInstance(Context context) {
		if (sAppDB == null) {
			sAppDB = new DBService(context);
		}
		return sAppDB;
	}

	public static boolean add(Object object) {
		boolean tag = true;
		long temp = -1;
		if (object instanceof HealthRecord) {
			temp = mHealthRecordDao.insertOrReplace((HealthRecord) object);
		} else if (object instanceof jwsjb) {
			temp = mJwsjbDao.insertOrReplace((jwsjb) object);
		} else if (object instanceof jwsss) {
			temp = mJwsssDao.insertOrReplace((jwsss) object);
		} else if (object instanceof jwssx) {
			temp = mJwssxDao.insertOrReplace((jwssx) object);
		} else if (object instanceof jwsws) {
			temp = mJwswsDao.insertOrReplace((jwsws) object);
		} else if (object instanceof base_info) {
			temp = mBase_infoDao.insertOrReplace((base_info) object);
		} else if (object instanceof Examination) {
			temp = mExaminationDao.insertOrReplace((Examination) object);
		} else if (object instanceof LifestySituation) {
			temp = mLifestySituationDao
					.insertOrReplace((LifestySituation) object);
		} else if (object instanceof AccessoryExamination) {
			temp = mAccessoryExaminationDao
					.insertOrReplace((AccessoryExamination) object);
		} else if (object instanceof InhospitalSituation) {
			temp = mInhospitalSituationDao
					.insertOrReplace((InhospitalSituation) object);
		} else if (object instanceof MedicineSituation) {
			temp = mMedicineSituationDao
					.insertOrReplace((MedicineSituation) object);
		} else if (object instanceof NonimmuneInoculation) {
			temp = mNonimmuneInoculationDao
					.insertOrReplace((NonimmuneInoculation) object);
		} else if (object instanceof HealthAssessment) {
			temp = mHealthAssessmentDao
					.insertOrReplace((HealthAssessment) object);
		} else if (object instanceof Visit_info) {
			temp = mVisit_infoDao.insertOrReplace((Visit_info) object);
		} else if (object instanceof Visit_info2) {
			temp = mVisit_info2Dao.insertOrReplace((Visit_info2) object);
		} else if (object instanceof ChineseMedicineManage) {
			temp = mChineseMedicineManageDao
					.insertOrReplace((ChineseMedicineManage) object);
		} else if (object instanceof OldPeopleSelfCare) {
			temp = mOldPeopleSelfCareDao
					.insertOrReplace((OldPeopleSelfCare) object);
		} else if (object instanceof xueya) {
			temp = mxueyaDao.insertOrReplace((xueya) object);
		} else if (object instanceof xueyang) {
			temp = mxueyangDao.insertOrReplace((xueyang) object);
		} else if (object instanceof tiwen) {
			temp = mtiwenDao.insertOrReplace((tiwen) object);
		} else if (object instanceof xuetang) {
			temp = mxuetangDao.insertOrReplace((xuetang) object);
		} else if (object instanceof niaoye) {
			temp = mniaoyeDao.insertOrReplace((niaoye) object);
		} else if (object instanceof xindian) {
			temp = mxindianDao.insertOrReplace((xindian) object);
		} else if (object instanceof UploadRecord) {
			temp = mUploadRecordDao.insertOrReplace((UploadRecord) object);
		} else if (object instanceof xuezhi) {
			temp = mXuezhiDao.insertOrReplace((xuezhi) object);
		} else if (object instanceof VisitPlan) {
			temp = mVisitPlanDao.insertOrReplace((VisitPlan) object);
		}

		else {
			tag = false;
		}
		if (temp < 0) {
			tag = false;
		}
		return tag;
	}

	public static void update(Object object) {
		boolean tag = true;
		if (object instanceof HealthRecord) {
			mHealthRecordDao.update((HealthRecord) object);
		} else if (object instanceof jwsjb) {
			mJwsjbDao.update((jwsjb) object);
		} else if (object instanceof jwsss) {
			mJwsssDao.update((jwsss) object);
		} else if (object instanceof jwssx) {
			mJwssxDao.update((jwssx) object);
		} else if (object instanceof jwsws) {
			mJwswsDao.update((jwsws) object);
		} else if (object instanceof base_info) {
			mBase_infoDao.update((base_info) object);
		} else if (object instanceof Examination) {
			mExaminationDao.update((Examination) object);
		} else if (object instanceof LifestySituation) {
			mLifestySituationDao.update((LifestySituation) object);
		} else if (object instanceof AccessoryExamination) {
			mAccessoryExaminationDao.update((AccessoryExamination) object);
		} else if (object instanceof InhospitalSituation) {
			mInhospitalSituationDao.update((InhospitalSituation) object);
		} else if (object instanceof MedicineSituation) {
			mMedicineSituationDao.update((MedicineSituation) object);
		} else if (object instanceof NonimmuneInoculation) {
			mNonimmuneInoculationDao.update((NonimmuneInoculation) object);
		} else if (object instanceof HealthAssessment) {
			mHealthAssessmentDao.update((HealthAssessment) object);
		} else if (object instanceof Visit_info) {
			mVisit_infoDao.update((Visit_info) object);
		} else if (object instanceof Visit_info2) {
			mVisit_info2Dao.update((Visit_info2) object);
		} else if (object instanceof ChineseMedicineManage) {
			mChineseMedicineManageDao.update((ChineseMedicineManage) object);
		} else if (object instanceof OldPeopleSelfCare) {
			mOldPeopleSelfCareDao.update((OldPeopleSelfCare) object);
		} else if (object instanceof xueya) {
			mxueyaDao.update((xueya) object);
		} else if (object instanceof xueyang) {
			mxueyangDao.update((xueyang) object);
		} else if (object instanceof tiwen) {
			mtiwenDao.update((tiwen) object);
		} else if (object instanceof xuetang) {
			mxuetangDao.update((xuetang) object);
		} else if (object instanceof niaoye) {
			mniaoyeDao.update((niaoye) object);
		} else if (object instanceof xindian) {
			mxindianDao.update((xindian) object);
		} else if (object instanceof UploadRecord) {
			mUploadRecordDao.update((UploadRecord) object);
		} else if (object instanceof xuezhi) {
			mXuezhiDao.update((xuezhi) object);
		} else if (object instanceof VisitPlan) {
			mVisitPlanDao.update((VisitPlan) object);
		}
	}

	/** 通过对象获取所有的集合数据。 */
	public static List<Object> getAll(Object object) {
		if (object instanceof HealthRecord) {
			return new ArrayList<Object>(mHealthRecordDao.loadAll());
		} else if (object instanceof jwsjb) {
			return new ArrayList<Object>(mJwsjbDao.loadAll());
		} else if (object instanceof jwsss) {
			return new ArrayList<Object>(mJwsssDao.loadAll());
		} else if (object instanceof jwssx) {
			return new ArrayList<Object>(mJwssxDao.loadAll());
		} else if (object instanceof jwsws) {
			return new ArrayList<Object>(mJwswsDao.loadAll());
		} else if (object instanceof base_info) {
			return new ArrayList<Object>(mBase_infoDao.loadAll());
		} else if (object instanceof Examination) {
			return new ArrayList<Object>(mExaminationDao.loadAll());
		} else if (object instanceof AccessoryExamination) {
			return new ArrayList<Object>(mAccessoryExaminationDao.loadAll());
		} else if (object instanceof InhospitalSituation) {
			return new ArrayList<Object>(mInhospitalSituationDao.loadAll());
		} else if (object instanceof MedicineSituation) {
			return new ArrayList<Object>(mMedicineSituationDao.loadAll());
		} else if (object instanceof NonimmuneInoculation) {
			return new ArrayList<Object>(mNonimmuneInoculationDao.loadAll());
		} else if (object instanceof HealthAssessment) {
			return new ArrayList<Object>(mHealthAssessmentDao.loadAll());
		} else if (object instanceof Visit_info) {
			return new ArrayList<Object>(mVisit_infoDao.loadAll());
		} else if (object instanceof Visit_info2) {
			return new ArrayList<Object>(mVisit_info2Dao.loadAll());
		} else if (object instanceof ChineseMedicineManage) {
			return new ArrayList<Object>(mChineseMedicineManageDao.loadAll());
		} else if (object instanceof OldPeopleSelfCare) {
			return new ArrayList<Object>(mOldPeopleSelfCareDao.loadAll());
		} else if (object instanceof LifestySituation) {
			return new ArrayList<Object>(mLifestySituationDao.loadAll());
		} else if (object instanceof xueya) {
			return new ArrayList<Object>(mxueyaDao.loadAll());
		} else if (object instanceof xueyang) {
			return new ArrayList<Object>(mxueyangDao.loadAll());
		} else if (object instanceof tiwen) {
			return new ArrayList<Object>(mtiwenDao.loadAll());
		} else if (object instanceof xuetang) {
			return new ArrayList<Object>(mxuetangDao.loadAll());
		} else if (object instanceof niaoye) {
			return new ArrayList<Object>(mniaoyeDao.loadAll());
		} else if (object instanceof xindian) {
			return new ArrayList<Object>(mxindianDao.loadAll());
		} else if (object instanceof UploadRecord) {
			return new ArrayList<Object>(mUploadRecordDao.loadAll());
		} else if (object instanceof xuezhi) {
			return new ArrayList<Object>(mXuezhiDao.loadAll());
		} else if (object instanceof VisitPlan) {
			return new ArrayList<Object>(mVisitPlanDao.loadAll());
		}
		return null;
	}

	/***
	 * 通过唯一性来查询数据的。
	 * 
	 * @param object
	 * @return
	 */
	public static Object queryByKey(Object object) {
		if (object instanceof HealthRecord) {
			return mHealthRecordDao
					.queryBuilder()
					.where(HealthRecordDao.Properties.Time
							.eq(((HealthRecord) object).getTime() + "")).list();
		} else if (object instanceof jwsjb) {
			return mJwsjbDao
					.queryBuilder()
					.where(jwsjbDao.Properties.IdCard.eq(((jwsjb) object)
							.getIdCard() + "")).list();
		} else if (object instanceof jwsss) {
			return mJwsssDao
					.queryBuilder()
					.where(jwsssDao.Properties.IdCard.eq(((jwsss) object)
							.getIdCard() + "")).list();
		} else if (object instanceof jwssx) {
			return mJwssxDao
					.queryBuilder()
					.where(jwssxDao.Properties.IdCard.eq(((jwssx) object)
							.getIdCard() + "")).list();
		} else if (object instanceof jwsws) {
			return mJwswsDao
					.queryBuilder()
					.where(jwswsDao.Properties.IdCard.eq(((jwsws) object)
							.getIdCard() + "")).list();
		} else if (object instanceof base_info) {
			return mBase_infoDao
					.queryBuilder()
					.where(base_infoDao.Properties.Time.eq(((base_info) object)
							.getTime() + "")).list();
		} else if (object instanceof Examination) {
			return mExaminationDao
					.queryBuilder()
					.where(ExaminationDao.Properties.Time
							.eq(((Examination) object).getTime() + "")).list();
		} else if (object instanceof AccessoryExamination) {
			return mAccessoryExaminationDao
					.queryBuilder()
					.where(AccessoryExaminationDao.Properties.Time
							.eq(((AccessoryExamination) object).getTime() + ""))
					.list();
		} else if (object instanceof InhospitalSituation) {
			return mInhospitalSituationDao
					.queryBuilder()
					.where(InhospitalSituationDao.Properties.Time
							.eq(((InhospitalSituation) object).getTime() + ""))
					.list();
		} else if (object instanceof MedicineSituation) {
			return mMedicineSituationDao
					.queryBuilder()
					.where(MedicineSituationDao.Properties.Time
							.eq(((MedicineSituation) object).getTime() + ""))
					.list();
		} else if (object instanceof NonimmuneInoculation) {
			return mNonimmuneInoculationDao
					.queryBuilder()
					.where(NonimmuneInoculationDao.Properties.Time
							.eq(((NonimmuneInoculation) object).getTime() + ""))
					.list();
		} else if (object instanceof HealthAssessment) {
			return mHealthAssessmentDao
					.queryBuilder()
					.where(HealthAssessmentDao.Properties.Time
							.eq(((HealthAssessment) object).getTime() + ""))
					.list();
		} else if (object instanceof Visit_info) {
			return mVisit_infoDao
					.queryBuilder()
					.where(Visit_infoDao.Properties.Time
							.eq(((Visit_info) object).getTime() + "")).list();
		} else if (object instanceof Visit_info2) {
			return mVisit_info2Dao
					.queryBuilder()
					.where(Visit_info2Dao.Properties.Time
							.eq(((Visit_info2) object).getTime() + "")).list();
		} else if (object instanceof ChineseMedicineManage) {
			return mChineseMedicineManageDao
					.queryBuilder()
					.where(ChineseMedicineManageDao.Properties.Time
							.eq(((ChineseMedicineManage) object).getTime() + ""))
					.list();
		} else if (object instanceof OldPeopleSelfCare) {
			return mOldPeopleSelfCareDao
					.queryBuilder()
					.where(OldPeopleSelfCareDao.Properties.Time
							.eq(((OldPeopleSelfCare) object).getTime() + ""))
					.list();
		} else if (object instanceof LifestySituation) {
			return mLifestySituationDao
					.queryBuilder()
					.where(LifestySituationDao.Properties.Time
							.eq(((LifestySituation) object).getTime() + ""))
					.list();
		} else if (object instanceof xueya) {
			return mxueyaDao
					.queryBuilder()
					.where(xueyaDao.Properties.Time.eq(((xueya) object)
							.getTime() + "")).list();
		} else if (object instanceof xueyang) {
			return mxueyangDao
					.queryBuilder()
					.where(xueyangDao.Properties.Time.eq(((xueyang) object)
							.getTime() + "")).list();
		} else if (object instanceof tiwen) {
			return mtiwenDao
					.queryBuilder()
					.where(tiwenDao.Properties.Time.eq(((tiwen) object)
							.getTime() + "")).list();
		} else if (object instanceof xuetang) {
			return mxuetangDao
					.queryBuilder()
					.where(xuetangDao.Properties.Time.eq(((xuetang) object)
							.getTime() + "")).list();
		} else if (object instanceof niaoye) {
			return mniaoyeDao
					.queryBuilder()
					.where(niaoyeDao.Properties.Time.eq(((niaoye) object)
							.getTime() + "")).list();
		} else if (object instanceof xindian) {
			return mxindianDao
					.queryBuilder()
					.where(xindianDao.Properties.Time.eq(((xindian) object)
							.getTime() + "")).list();
		} else if (object instanceof UploadRecord) {
			return mUploadRecordDao
					.queryBuilder()
					.where(UploadRecordDao.Properties.Time
							.eq(((UploadRecord) object).getTime() + "")).list();
		} else if (object instanceof xuezhi) {
			return mXuezhiDao
					.queryBuilder()
					.where(xuezhiDao.Properties.Time.eq(((xuezhi) object)
							.getTime() + "")).list();
		} else if (object instanceof VisitPlan) {
			return mVisitPlanDao
					.queryBuilder()
					.where(VisitPlanDao.Properties.Idcard
							.eq(((VisitPlan) object).getIdcard() + "")).list();
		}
		return object;
	}

	/***
	 * 通过时间获取上传的记录。
	 * 
	 * @param time
	 * @return
	 */
	public static UploadRecord getUploadRecordByTime(String time) {
		UploadRecord result = null;
		UploadRecord ur = new UploadRecord();
		ur.setTime(time);
		List<UploadRecord> lists = (List<UploadRecord>) DBService
				.queryByKey(ur);
		if (lists != null && lists.size() > 0) {
			result = lists.get(0);
		}
		return result;
	}

	public static Object queryBydIdCardAndTime(Object object) {
		if (object instanceof base_info) {
			return mBase_infoDao
					.queryBuilder()
					.where(base_infoDao.Properties.IdCard
							.eq(((base_info) object).getIdCard() + ""))
					.where(base_infoDao.Properties.Time.eq(((base_info) object)
							.getTime() + "")).list();
		} else if (object instanceof Examination) {
			return mExaminationDao
					.queryBuilder()
					.where(ExaminationDao.Properties.Time
							.eq(((Examination) object).getTime() + "")).list();
		} else if (object instanceof AccessoryExamination) {
			return mAccessoryExaminationDao
					.queryBuilder()
					.where(AccessoryExaminationDao.Properties.Time
							.eq(((AccessoryExamination) object).getTime() + ""))
					.list();
		} else if (object instanceof InhospitalSituation) {
			return mInhospitalSituationDao
					.queryBuilder()
					.where(InhospitalSituationDao.Properties.Time
							.eq(((InhospitalSituation) object).getTime() + ""))
					.list();
		} else if (object instanceof MedicineSituation) {
			return mMedicineSituationDao
					.queryBuilder()
					.where(MedicineSituationDao.Properties.Time
							.eq(((MedicineSituation) object).getTime() + ""))
					.list();
		} else if (object instanceof NonimmuneInoculation) {
			return mNonimmuneInoculationDao
					.queryBuilder()
					.where(NonimmuneInoculationDao.Properties.Time
							.eq(((NonimmuneInoculation) object).getTime() + ""))
					.list();
		} else if (object instanceof HealthAssessment) {
			return mHealthAssessmentDao
					.queryBuilder()
					.where(HealthAssessmentDao.Properties.Time
							.eq(((HealthAssessment) object).getTime() + ""))
					.list();
		} else if (object instanceof Visit_info) {
			return mVisit_infoDao
					.queryBuilder()
					.where(Visit_infoDao.Properties.IdCard
							.eq(((Visit_info) object).getIdCard() + "")).list();
		} else if (object instanceof Visit_info2) {
			return mVisit_info2Dao
					.queryBuilder()
					.where(Visit_info2Dao.Properties.IdCard
							.eq(((Visit_info2) object).getIdCard() + ""))
					.list();
		} else if (object instanceof ChineseMedicineManage) {
			return mChineseMedicineManageDao
					.queryBuilder()
					.where(ChineseMedicineManageDao.Properties.IdCard
							.eq(((ChineseMedicineManage) object).getIdCard()
									+ "")).list();
		} else if (object instanceof OldPeopleSelfCare) {
			return mOldPeopleSelfCareDao
					.queryBuilder()
					.where(OldPeopleSelfCareDao.Properties.IdCard
							.eq(((OldPeopleSelfCare) object).getIdCard() + ""))
					.list();
		} else if (object instanceof LifestySituation) {
			return mLifestySituationDao
					.queryBuilder()
					.where(LifestySituationDao.Properties.Time
							.eq(((LifestySituation) object).getTime() + ""))
					.list();
		} else if (object instanceof UploadRecord) {
			return mUploadRecordDao
					.queryBuilder()
					.where(UploadRecordDao.Properties.Time
							.eq(((UploadRecord) object).getTime() + "")).list();
		}
		return null;
	}

	/***
	 * 通过idcard来查询集合数据。
	 * 
	 * @param object
	 * @return
	 */
	public static Object queryByIdCard(Object object) {
		if (object instanceof HealthRecord) {
			return mHealthRecordDao
					.queryBuilder()
					.where(HealthRecordDao.Properties.IdCard
							.eq(((HealthRecord) object).getIdCard() + ""))
					.list();
		} else if (object instanceof jwsjb) {
			return mJwsjbDao
					.queryBuilder()
					.where(jwsjbDao.Properties.IdCard.eq(((jwsjb) object)
							.getIdCard() + "")).list();
		} else if (object instanceof jwsss) {
			return mJwsssDao
					.queryBuilder()
					.where(jwsssDao.Properties.IdCard.eq(((jwsss) object)
							.getIdCard() + "")).list();
		} else if (object instanceof jwssx) {
			return mJwssxDao
					.queryBuilder()
					.where(jwssxDao.Properties.IdCard.eq(((jwssx) object)
							.getIdCard() + "")).list();
		} else if (object instanceof jwsws) {
			return mJwswsDao
					.queryBuilder()
					.where(jwswsDao.Properties.IdCard.eq(((jwsws) object)
							.getIdCard() + "")).list();
		} else if (object instanceof base_info) {
			return mBase_infoDao
					.queryBuilder()
					.where(base_infoDao.Properties.IdCard
							.eq(((base_info) object).getIdCard() + "")).list();
		} else if (object instanceof Examination) {
			return mExaminationDao
					.queryBuilder()
					.where(ExaminationDao.Properties.Time
							.eq(((Examination) object).getTime() + "")).list();
		} else if (object instanceof AccessoryExamination) {
			return mAccessoryExaminationDao
					.queryBuilder()
					.where(AccessoryExaminationDao.Properties.Time
							.eq(((AccessoryExamination) object).getTime() + ""))
					.list();
		} else if (object instanceof InhospitalSituation) {
			return mInhospitalSituationDao
					.queryBuilder()
					.where(InhospitalSituationDao.Properties.Time
							.eq(((InhospitalSituation) object).getTime() + ""))
					.list();
		} else if (object instanceof MedicineSituation) {
			return mMedicineSituationDao
					.queryBuilder()
					.where(MedicineSituationDao.Properties.Time
							.eq(((MedicineSituation) object).getTime() + ""))
					.list();
		} else if (object instanceof NonimmuneInoculation) {
			return mNonimmuneInoculationDao
					.queryBuilder()
					.where(NonimmuneInoculationDao.Properties.Time
							.eq(((NonimmuneInoculation) object).getTime() + ""))
					.list();
		} else if (object instanceof HealthAssessment) {
			return mHealthAssessmentDao
					.queryBuilder()
					.where(HealthAssessmentDao.Properties.Time
							.eq(((HealthAssessment) object).getTime() + ""))
					.list();
		} else if (object instanceof Visit_info) {
			return mVisit_infoDao
					.queryBuilder()
					.where(Visit_infoDao.Properties.IdCard
							.eq(((Visit_info) object).getIdCard() + "")).list();
		} else if (object instanceof Visit_info2) {
			return mVisit_info2Dao
					.queryBuilder()
					.where(Visit_info2Dao.Properties.IdCard
							.eq(((Visit_info2) object).getIdCard() + ""))
					.list();
		} else if (object instanceof ChineseMedicineManage) {
			return mChineseMedicineManageDao
					.queryBuilder()
					.where(ChineseMedicineManageDao.Properties.IdCard
							.eq(((ChineseMedicineManage) object).getIdCard()
									+ "")).list();
		} else if (object instanceof OldPeopleSelfCare) {
			return mOldPeopleSelfCareDao
					.queryBuilder()
					.where(OldPeopleSelfCareDao.Properties.IdCard
							.eq(((OldPeopleSelfCare) object).getIdCard() + ""))
					.list();
		} else if (object instanceof LifestySituation) {
			return mLifestySituationDao
					.queryBuilder()
					.where(LifestySituationDao.Properties.Time
							.eq(((LifestySituation) object).getTime() + ""))
					.list();
		} else if (object instanceof xueya) {
			return mxueyaDao
					.queryBuilder()
					.where(xueyaDao.Properties.IdCard.eq(((xueya) object)
							.getIdCard() + "")).list();
		} else if (object instanceof xueyang) {
			return mxueyangDao
					.queryBuilder()
					.where(xueyangDao.Properties.IdCard.eq(((xueyang) object)
							.getIdCard() + "")).list();
		} else if (object instanceof tiwen) {
			return mtiwenDao
					.queryBuilder()
					.where(tiwenDao.Properties.IdCard.eq(((tiwen) object)
							.getIdCard() + "")).list();
		} else if (object instanceof xuetang) {
			return mxuetangDao
					.queryBuilder()
					.where(xuetangDao.Properties.IdCard.eq(((xuetang) object)
							.getIdCard() + "")).list();
		} else if (object instanceof niaoye) {
			return mniaoyeDao
					.queryBuilder()
					.where(niaoyeDao.Properties.IdCard.eq(((niaoye) object)
							.getIdCard() + "")).list();
		} else if (object instanceof xindian) {
			return mxindianDao
					.queryBuilder()
					.where(xindianDao.Properties.IdCard.eq(((xindian) object)
							.getIdCard() + "")).list();

		} else if (object instanceof UploadRecord) {
			return mUploadRecordDao
					.queryBuilder()
					.where(UploadRecordDao.Properties.IdCard
							.eq(((UploadRecord) object).getIdCard() + ""))
					.list();
		} else if (object instanceof xuezhi) {
			return mXuezhiDao
					.queryBuilder()
					.where(xuezhiDao.Properties.IdCard.eq(((xuezhi) object)
							.getIdCard() + "")).list();
		} else if (object instanceof VisitPlan) {
			return mVisitPlanDao
					.queryBuilder()
					.where(VisitPlanDao.Properties.Idcard.eq(((VisitPlan) object)
							.getIdcard() + "")).list();
		}
		return object;
	}

	/***
	 * 删除单条记录
	 * 
	 * @param object
	 */
	public static void delete(Object object) {
		if (object instanceof HealthRecord) {
			mHealthRecordDao.delete((HealthRecord) object);
		} else if (object instanceof jwsjb) {
			mJwsjbDao.delete((jwsjb) object);
		} else if (object instanceof jwsss) {
			mJwsssDao.delete((jwsss) object);
		} else if (object instanceof jwssx) {
			mJwssxDao.delete((jwssx) object);
		} else if (object instanceof jwsws) {
			mJwswsDao.delete((jwsws) object);
		} else if (object instanceof base_info) {
			mBase_infoDao.delete((base_info) object);
		} else if (object instanceof Examination) {
			mExaminationDao.delete((Examination) object);
		} else if (object instanceof AccessoryExamination) {
			mAccessoryExaminationDao.delete((AccessoryExamination) object);
		} else if (object instanceof InhospitalSituation) {
			mInhospitalSituationDao.delete((InhospitalSituation) object);
		} else if (object instanceof MedicineSituation) {
			mMedicineSituationDao.delete((MedicineSituation) object);
		} else if (object instanceof NonimmuneInoculation) {
			mNonimmuneInoculationDao.delete((NonimmuneInoculation) object);
		} else if (object instanceof HealthAssessment) {
			mHealthAssessmentDao.delete((HealthAssessment) object);
		} else if (object instanceof Visit_info) {
			mVisit_infoDao.delete((Visit_info) object);
		} else if (object instanceof Visit_info2) {
			mVisit_info2Dao.delete((Visit_info2) object);
		} else if (object instanceof ChineseMedicineManage) {
			mChineseMedicineManageDao.delete((ChineseMedicineManage) object);
		} else if (object instanceof OldPeopleSelfCare) {
			mOldPeopleSelfCareDao.delete((OldPeopleSelfCare) object);
		} else if (object instanceof LifestySituation) {
			mLifestySituationDao.delete((LifestySituation) object);
		} else if (object instanceof xueya) {
			mxueyaDao.delete((xueya) object);
		} else if (object instanceof xueyang) {
			mxueyangDao.delete((xueyang) object);
		} else if (object instanceof tiwen) {
			mtiwenDao.delete((tiwen) object);
		} else if (object instanceof xuetang) {
			mxuetangDao.delete((xuetang) object);
		} else if (object instanceof niaoye) {
			mniaoyeDao.delete((niaoye) object);
		} else if (object instanceof xindian) {
			mxindianDao.delete((xindian) object);
		} else if (object instanceof UploadRecord) {
			mUploadRecordDao.delete((UploadRecord) object);
		} else if (object instanceof xuezhi) {
			mXuezhiDao.delete((xuezhi) object);
		} else if (object instanceof VisitPlan) {
			mVisitPlanDao.delete((VisitPlan) object);
		}
	}

	/** 删除该对象对应的所有数据。 */
	public static void deleteAll(Object object) {
		if (object instanceof HealthRecord) {
			mHealthRecordDao.deleteAll();
		} else if (object instanceof jwsjb) {
			mJwsjbDao.deleteAll();
		} else if (object instanceof jwsss) {
			mJwsssDao.deleteAll();
		} else if (object instanceof jwssx) {
			mJwssxDao.deleteAll();
		} else if (object instanceof jwsws) {
			mJwswsDao.deleteAll();
		} else if (object instanceof base_info) {
			mBase_infoDao.deleteAll();
		} else if (object instanceof Examination) {
			mExaminationDao.deleteAll();
		} else if (object instanceof AccessoryExamination) {
			mAccessoryExaminationDao.deleteAll();
		} else if (object instanceof InhospitalSituation) {
			mInhospitalSituationDao.deleteAll();
		} else if (object instanceof MedicineSituation) {
			mMedicineSituationDao.deleteAll();
		} else if (object instanceof NonimmuneInoculation) {
			mNonimmuneInoculationDao.deleteAll();
		} else if (object instanceof HealthAssessment) {
			mHealthAssessmentDao.deleteAll();
		} else if (object instanceof Visit_info) {
			mVisit_infoDao.deleteAll();
		} else if (object instanceof Visit_info2) {
			mVisit_info2Dao.deleteAll();
		} else if (object instanceof ChineseMedicineManage) {
			mChineseMedicineManageDao.deleteAll();
		} else if (object instanceof OldPeopleSelfCare) {
			mOldPeopleSelfCareDao.deleteAll();
		} else if (object instanceof LifestySituation) {
			mLifestySituationDao.deleteAll();
		} else if (object instanceof xueya) {
			mxueyaDao.deleteAll();
		} else if (object instanceof xueyang) {
			mxueyangDao.deleteAll();
		} else if (object instanceof tiwen) {
			mtiwenDao.deleteAll();
		} else if (object instanceof xuetang) {
			mxuetangDao.deleteAll();
		} else if (object instanceof niaoye) {
			mniaoyeDao.deleteAll();
		} else if (object instanceof xindian) {
			mxindianDao.deleteAll();
		} else if (object instanceof UploadRecord) {
			mUploadRecordDao.deleteAll();
		} else if (object instanceof xuezhi) {
			mXuezhiDao.deleteAll();
		} else if (object instanceof VisitPlan) {
			mVisitPlanDao.deleteAll();
		}
	}

}
